package com.crm.controller;

import com.crm.controller.util.R;
import com.crm.pojo.Contact;
import com.crm.pojo.client;
import com.crm.service.contactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/contact")
public class contactController {
    @Autowired
    private contactService service;

    @GetMapping("/{uid}")
    public R selectAll(@PathVariable int uid){
        List<Contact> list = service.selectAll(uid);
        return new R(true,list,true? "查询成功":"查询失败");
    }
    @GetMapping("/{uid}/{key}")
    public R selectByKey(@PathVariable int uid,@PathVariable String key){
        String key1 = "%"+key+"%";//很重要 模糊查询必备
        List<Contact> list = service.selectByKey(uid,key1);
        return new R(true,list,true? "查询成功":"查询失败");
    }
    @PostMapping
    public R save(@RequestBody Contact contact){
        boolean flag = service.save(contact);
        return new R(flag,null,flag? "添加成功":"添加失败");
    }
    @PutMapping
    public R updateById(@RequestBody Contact contact){
        boolean flag = service.updateById(contact);
        return new R(flag,null,flag? "修改成功":"修改失败");
    }
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable int id){
        boolean flag = service.deleteById(id);
        return new R(flag,null,flag? "删除成功":"删除失败");
    }
}
